﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CharacterAction : MonoBehaviour
{
    Rigidbody2D rigi;
    public GameObject point;

    private Image image;
    public Sprite imageSprite;
    public Sprite imageIdleSprite;

    private void Awake()
    {
        rigi = transform.GetComponent<Rigidbody2D>();
        transform.up = (point.transform.position - transform.position).normalized;
        image = GetComponent<Image>();
        
    }

    /// <summary>
    /// 开局动画中的角色动画
    /// </summary>
    private void Update()
    {
        if (rigi.velocity.x > 0f)
        {
            image.sprite = imageSprite;
            transform.localScale = new Vector3(1, 1, 1);
        }
        else if (rigi.velocity.x < 0f)
        {
            image.sprite = imageSprite;
            transform.localScale = new Vector3(-1, 1, 1);

        }
        else
        {
            transform.localScale = new Vector3(1, 1, 1);
            image.sprite = imageIdleSprite;
        }

        if (rigi.velocity.y == 0f)
        {
            rigi.AddForce(rigi.velocity.normalized * 0.1f, ForceMode2D.Impulse);
        }
    }





}
